package com.animee.jiujiangdict.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.animee.jiujiangdict.R;
import com.animee.jiujiangdict.bean.PinyinWordBean;
import java.util.List;
/*  拼音列表界面，GridView的适配器*/
public class PinyinGridAdapter extends BaseAdapter {
    Context context;
    List<PinyinWordBean.ResultBean.ListBean> mDatas;

    public PinyinGridAdapter(Context context, List<PinyinWordBean.ResultBean.ListBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }
    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_pgv,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        PinyinWordBean.ResultBean.ListBean bean = mDatas.get(position);
        holder.tv.setText(bean.getZi());
        return convertView;
    }
    class ViewHolder{
        TextView tv;
        public ViewHolder(View view){
            tv = view.findViewById(R.id.item_sgv_tv);
        }
    }
}
